package com.cmcc.linlaker.volley;

import com.android.volley.Request;
import com.android.volley.RequestQueue;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.Volley;
import com.cmcc.linlaker.application.LinhuApp;

public class VolleyHelper implements Response.Listener,Response.ErrorListener{

    private static VolleyHelper instance = new VolleyHelper();
    private RequestQueue requestQueue;

    private VolleyHelper()
    {
        requestQueue = Volley.newRequestQueue(LinhuApp.getContext());
    }

    public static VolleyHelper getInstance()
    {
        return instance;
    }

    public void addRequest(Request req, Object tag)
    {
        req.setTag(tag);
        addRequest(req);
    }

    public void addRequest(Request req)
    {
        requestQueue.add(req);
    }

    public void cancelAllByTag(Object tag)
    {
        if(tag != null)
            requestQueue.cancelAll(tag);
    }

    public void cancelAll(RequestQueue.RequestFilter filter)
    {
        requestQueue.cancelAll(filter);
    }

    @Override
    public void onErrorResponse(VolleyError error) {

    }

    @Override
    public void onResponse(Object response) {
    }

    public RequestQueue getRequestQueue() {
        return requestQueue;
    }
}
